#ifndef _CONT_TERM_
#define _CONT_TERM_

#include "../DF_Common/basis_state.h"
#include "../DF_Common/const_nucl.h"
#include "../DF_Common/coupling_coeff.h"
#include "../DF_Common/progress_bar.h"
#include "../DF_Mpi_Sep/wavefun_coeff.h"
#include <fstream>
#include <iostream>

using std::cout;
using std::endl;
using std::vector;

class Cont_term {
public:
  Cont_term(LEC_CONST &lec_t, Wave_Fun &wave_t, SixJ_coeff &sixJ_t,
            Jacobi &jaco_t)
      : LECs(lec_t), wave(wave_t), sixJ(sixJ_t), jaco(jaco_t) {}

  const LEC_CONST &LECs;
  const Wave_Fun &wave;
  const SixJ_coeff &sixJ;
  const Jacobi &jaco;

  double pf_cont;
  vector<vector<vector<double>>> vec; // vec[channel][jaco_index a][jaco_index
                                      // b]
  vector<vector<double>> PFK_cont_vec;

  double quick(int ch, int final_index, int init_index) {
    if (jaco.state[ch][final_index].F < 0 || jaco.state[ch][init_index].I < 0) {
      cout << "Wrong happened at Cont_term:quick F or I < 0 !!" << endl;
      exit(0);
    }
    return vec[ch][final_index][init_index];
  }

  void init(int n_max);
  double cal(const State_Jacobi &final_state, const State_Jacobi &init_state);
  void build();
  void print();
  void print(int channel_num);
  void print(std::string filename);

private:
  void PFK_cont_cal(int n_max);
  int Tri(int &j2a, int &j2b, int &j2c);
  int Tri(const int &j2a, const int &j2b, const int &j2c) {
    int A = j2a;
    int B = j2b;
    int C = j2c;
    return Tri(A, B, C);
  }
  int Tri_state(const State_Jacobi &state);
  int phase(int n);
};

#endif
